//
// Created by 12992 on 24-11-7.
//

// You may need to build the project (run Qt uic code generator) to get "ui_TranscoderQueueWidget.h" resolved

#include "transcoderqueuewidget.h"
#include "video_meta.h"
#include "process.hpp"
#include "QueueItem.h"
#include <QHBoxLayout>

#include "ui_TranscoderQueueWidget.h"

namespace gui::widgets
{
    TranscoderQueueWidget::TranscoderQueueWidget(QWidget* parent) : QWidget(parent), ui(new Ui::TranscoderQueueWidget),
                                                                    list(new QListWidget(this))
    {
        ui->setupUi(this);
        auto layout = new QHBoxLayout(this);
        layout->addWidget(this->list);
        this->setLayout(layout);
    }

    TranscoderQueueWidget::~TranscoderQueueWidget()
    {
        delete ui;
    }

    void TranscoderQueueWidget::addProcess(const std::string& name, std::shared_ptr<utils::process> process)
    {
        const auto item = new QListWidgetItem(this->list);
        item->setSizeHint(QSize(100, 60));
        auto* widget = new QueueItem(this->list->count(), name.c_str(), std::move(process));
        this->list->setItemWidget(item, widget);
        connect(widget, &QueueItem::errorOccurred, this, &TranscoderQueueWidget::errorOccurred);
    }
} // gui::widgets
